﻿using System;
using System.Collections.Generic;

using System.Windows;
using System.Windows.Controls;

using System.Windows.Input;
using System.Windows.Navigation;

using EagleJournal.Controls;

namespace EagleJournal
{
    public struct ClientContact
    {
        public string Type;
        public string Value;
    }

	public partial class PanelClientInfo : UserControl
	{
        public static readonly  RoutedEvent
            InvokeClientEditEvent       = EventManager.RegisterRoutedEvent("InvokeClientEdit", RoutingStrategy.Direct, typeof(RoutedEventHandler), typeof(PanelClientInfo));
        public event            RoutedEventHandler
            InvokeClientEdit
        {
            add     { this.AddHandler(InvokeClientEditEvent, value); }
            remove  { this.RemoveHandler(InvokeClientEditEvent, value); }
        }

        public static readonly  RoutedEvent
            InvokeClientOrdersEvent     = EventManager.RegisterRoutedEvent("InvokeClientOrders", RoutingStrategy.Direct, typeof(RoutedEventHandler), typeof(PanelClientInfo));
        public event            RoutedEventHandler
            InvokeClientOrders
        {
            add     { this.AddHandler(InvokeClientOrdersEvent, value); }
            remove  { this.RemoveHandler(InvokeClientOrdersEvent, value); }
        }

		public          PanelClientInfo     ()
		{
			this.InitializeComponent();
		}
            
        private void    ButtonEdit_Click    (object sender, RoutedEventArgs e)
        {
            this.RaiseEvent(new RoutedEventArgs(InvokeClientEditEvent));
        }
        private void    ButtonOrders_Click  (object sender, RoutedEventArgs e)
        {
            this.RaiseEvent(new RoutedEventArgs(InvokeClientOrdersEvent));
        }

        public  void    ClearData           ()
        {
            this.TextContactName.Text = string.Empty;
            this.DataContacts.Items.Clear();
        }
        public  void    PassData            (int ID, string name, List<ClientContact> contact)
        {
            this.TextContactName.Text = name;

            foreach (ClientContact row in contact)
            {
                ListClientContact list = new ListClientContact()
                {
                    ClientContactEditMode   = false,
                    ClientContactType       = row.Type,
                    Content                 = row.Value,
                };

                this.DataContacts.Items.Add(list);
            }
        }
	}
}